import { defineStore } from 'pinia';
import axios from '@/https';
import json5 from 'json5';

interface ISystemConfig {
  SysTitle: string;
}

export const useSysConfigStore = defineStore('sysConfig', {
  state: () => {
    return {
      sysConfig: {} as ISystemConfig
    };
  },
  actions: {
    getSystemConfig: async function () {
      try {
        const { data: res } = await axios.get(
          '/public/config/app.config.json5'
        );
        const config = json5.parse(res);
        this.sysConfig =
          import.meta.env.MODE === 'development'
            ? config.DevConfig
            : config.ProductionConfig;
      } catch (e: any) {
        console.log('配置文件不存在', e.message);
      }
    }
  }
});
